﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FightTheDragon.Managers;
using FightTheDragon.Interface;
using FightTheDragon.GameObjects;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace FightTheDragon.States
{
    class ExitState: BaseState
    {
        private InterfaceManager m_Interface;
        private InputManager m_Input;
        private StateManager m_States;
        private Text m_Exit;
        private Cursor m_Cursor;
        public enum States { YES = 2, NO };

        public ExitState()
        {
            m_Interface = null;
            m_Input = null;
            m_States = null;
            m_Exit = new Text();
            m_Cursor = new Cursor();

        }
        void BaseState.Enter()
        {
            m_Interface = InterfaceManager.Instance;
            m_Input = InputManager.Instance;
            m_States = StateManager.Instance;
            m_Exit = new Text(1280 / 2, 760 / 2, 0, "SpriteFont1", "Do you Want to Exit?\nYes\nNo", 1, Color.Red, 0, new RotateEffect(true));
            m_Cursor = new Cursor(0, "MMeteor", .5f, Color.White, 1, m_Exit, 2, 3);
            m_Interface.Add(m_Exit);
            m_Interface.Add(m_Cursor);
        }
        void BaseState.Exit()
        {
            m_Interface.RemoveAll();
        }
        bool BaseState.HandleInput()
        {
            if (m_Input.ButtonPressedOnce(Buttons.LeftThumbstickUp) || m_Input.ButtonPressedOnce(Buttons.DPadUp))
                m_Cursor.CursorMovement--;
            if (m_Input.ButtonPressedOnce(Buttons.LeftThumbstickDown) || m_Input.ButtonPressedOnce(Buttons.DPadDown))
                m_Cursor.CursorMovement++;
            if (m_Input.ButtonPressedOnce(Buttons.B))
                m_States.PopState();

            if (m_Input.ButtonPressedOnce(Buttons.A))
            {


                switch (m_Cursor.CursorMovement)
                {
                    case (int)States.YES:
                        m_States.ClearAllandEnter(new MMState());
                        break;
                    case (int)States.NO:
                        m_States.PopState();
                        break;
                }
            }


            return false;
        }
        void BaseState.Render()
        {
            m_Interface.Render();

        }
        void BaseState.Update(float gTime)
        {
            m_Input.Update();
            m_Interface.Update(gTime);
        }
    }
}
